﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace linkouqs.Gamekit {

    public sealed class CharacterAbilityDashAttack : CharacterAbility {

        [Range(1, 200)]
        public int damage = 20;
        
        [Range(0f, 3f)]
        [SerializeField]
        float m_RunTimeRequired = 0.6f;
        
        [Range(0f, 100f)]
        [SerializeField]
        float m_DashSpeed = 20f;
        float m_RunTimeCounter;

        public override bool CanStartAction() {

            if (IsInAnimation) {
                return false;
            }

            if (m_RunTimeCounter < m_RunTimeRequired) {
                return false;
            }

            if (Mathf.Approximately(Character.CharacterInput.Horizontal, 1f)) {
                return true;
            }

            if (Mathf.Approximately(Character.CharacterInput.Horizontal, -1f)) {
                return true;
            }

            return false;
        }

        public override void StartAction() {
            base.StartAction();
            Character.LockDirection = true;
            Character.Animator.SetTrigger("DashAttack");
        }

        public override void StopAction() {
            Character.LockDirection = false;
            base.StopAction();
        }

        void FixedUpdate() {

            if (IsInAnimation) {

                /// TODO.
                /// 
                /// 冲刺攻击动画
                /// 

                Character.Move((Character.IsLeft ? Vector2.left : Vector2.right) * m_DashSpeed * Time.fixedDeltaTime);

            }


            if (Character.IsGround && Character.IsPressedRun() && !IsInAnimation) {
                m_RunTimeCounter += Time.fixedDeltaTime;
            } else {
                m_RunTimeCounter = 0f;
            }

        }


    }

}
